package com.shengyo.model.service.impl;

import java.util.List;

import com.shengyo.model.bean.Computer;
import com.shengyo.model.dao.IComputerDAO;
import com.shengyo.model.service.IComputerService;

public class ComputerServiceImpl implements IComputerService{

	private IComputerDAO computerDAO;
	
	public IComputerDAO getComputerDAO() {
		return computerDAO;
	}

	public void setComputerDAO(IComputerDAO computerDAO) {
		this.computerDAO = computerDAO;
	}

	public ComputerServiceImpl() {
		super();
	}

	
	public void delete(int id) {
		Computer computer = this.findById(id);
		if(computer != null)
			computerDAO.delete(computer);
		
	}

	
	@SuppressWarnings("unchecked")
	public List<Computer> findAll() {
		return computerDAO.findAll();
	}

	
	public Computer findById(int id) {
		return (Computer) computerDAO.findById(id);
	}

	@Override
	public Computer saveOrUpdate(Computer computer) {
		computer = (Computer) computerDAO.save(computer);
		return computer;
	}

	@Override
	public Computer findByComputerUrl(String url) {
		return computerDAO.findByComputerUrl(url);
	}

}
